﻿/*
*打印log信息
*
*zsl,* zsl 2009/09/27
*
*用于打印log信息
*
** require:Core/Core.js
*
*/
	if(typeof FUI == 'undefined'){
		var FUI = {};
	}
    /**
    * @constructor
    */
    FUI.Logger = function() {
        this.init.apply(this, arguments);
    }
    FUI.Logger.prototype.init = function() {
        this.initMarkup();
        this.cache = ['以下是调试信息'];
        this.outputList = document.getElementById('outputList');
        this.container = document.getElementById('sparrow');
    }
    /*
    *   
    */
    FUI.Logger.prototype.initMarkup = function() {

        var div = document.createElement('div');
        div.id = "sparrow";
        var template = [
				  '<div class="top">',
				  '<span class="clear" id="sparrow_clear" title="清除"></span><span class="close" id="sparrow_close" title="关闭"></span>',
				  '</div>',
				  '<div class="main">',
				  '<ul id="outputList">',
				  '</ul>',
				  '</div>',
				  '<div class="bottom">',
				  '</div>'
				  ].join('');
        div.innerHTML = template;
        document.body.appendChild(div);
        this.initEvent();
    }
    FUI.Logger.prototype.initEvent = function() {
        var ua = navigator.userAgent.toLowerCase();
        var clear = document.getElementById('sparrow_clear');
        var close = document.getElementById('sparrow_close');
        clear.onclick = this.createClearClick(this);
        close.onclick = this.createCloseClick(this);
        //if (/msie/.test(ua)) {
            window.onresize = window.onscroll = this.Fixed(this);
       // }
    }
    /*
    @description    清除打印控制台
    */
    FUI.Logger.prototype.createClearClick = function(me) {
        return function() {
            me.outputList.innerHTML = '';
        }
    }
    /*
    @description    关闭打印控制台
    */
    FUI.Logger.prototype.createCloseClick = function(me) {
        return function() {
            document.body.removeChild(me.container);
        }
    }
    /*
    @description 添加log信息
    */
    FUI.Logger.prototype.addMessage = function(message, type) {
        var type = type || 'debug';
        var newMsg = document.createElement('LI');
        newMsg.className = type;
        newMsg.innerHTML = ['<span class="icon"></span>', message].join('');
        this.outputList.appendChild(newMsg);
        this.outputList.scrollTop = this.outputList.scrollHeight;
    }
    /*
    用于iex下position:fixed修补
    */
    FUI.Logger.prototype.Fixed = function(me) {
        return function() {
            var obj = me.container;
            var cheight = 380 || obj.offsetHeight || obj.clientHeight;
            var de = document.documentElement;
            var winHeight = de.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
            var scrollT = self.pageYOffset || (de && de.scrollTop) || document.body.scrollTop;
            obj.style.top = scrollT + winHeight - cheight + 'px';
        }
    }


    if (typeof console === 'undefined' || !console) {
        window.console={};
        var logger = null;
        window.console.log = function(message, type) {
            if (!logger) {
                logger = new FUI.Logger();
            }
            logger.addMessage(message, type);
        }
    }
